<template>
  <div>
    <el-table :data="list" :show-header="false" style="width: 100%">
      <el-table-column class-name="main">
        <template v-slot="{ row }">
          <span class="main">{{ row.main }}</span>
        </template>
      </el-table-column>
      <el-table-column>
        <template v-slot="{ row }">
          <el-image v-for="url in row.image" :key="url" :src="url | imgurl" :preview-src-list="row.image | imgurl" />
        </template>
      </el-table-column>
      <el-table-column class-name="main" width="160">
        <template v-slot="{ row }">
          <el-rate :value="row.evaluate / 2" disabled show-score text-color="#ff9900"> </el-rate>
        </template>
      </el-table-column>
      <el-table-column width="180">
        <template v-slot="{ row }">
          {{ row.createdAt | date }}
        </template>
      </el-table-column>
      <el-table-column width="120">
        <template v-slot="{ row }">
          <el-button type="text" icon="el-icon-view" @click="details(row)"> 查看详情 </el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination
        background
        layout="total, prev, pager, next, sizes, jumper"
        :current-page="query.page"
        :page-size="query.size"
        :page-sizes="pageSizes"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import { allmsg } from '@/api/user'
import { clientAddress } from '@/config'

export default {
  data() {
    return {
      list: [],
      total: 0,
      pageSizes: [5, 10, 20],
      query: {
        page: 1,
        size: 10,
      },
    }
  },
  methods: {
    async init() {
      const data = await allmsg(this.query)
      if (data.code !== 200) return this.$message.error('获取信息失败,刷新页面重试,错误码:' + data.code)
      this.list = data.data
      this.total = data.total
    },
    details(row) {
      window.open(clientAddress + '/comment-reply?id=' + row.id)
    },
    // 分页导航
    handlePageChange(val) {
      console.log(11)
      this.$set(this.query, 'page', val)
      this.init()
    },
    handleSizeChange(v) {
      this.query.size = v
      this.init()
    },
  },
  created() {
    this.init()
  },
}
</script>

<style lang="scss" scoped></style>
